package com.bkgy.modular.tbcountinuous.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bkgy.modular.tbcountinuous.dao.TbCountinuousDao;
import com.bkgy.modular.tbcountinuous.entity.TbCountinuousReq;
import com.bkgy.modular.tbcountinuous.entity.TbCountinuousRollingSteelGrade;
import com.bkgy.modular.tbcountinuous.service.TbCountinuousService;
import com.bkgy.sys.common.entity.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Author:Lipeng Zhao
 * Description:
 *
 * @Date:Created In 9:55 2025/11/26
 */
@Service
public class TbCountinuousServiceImpl extends ServiceImpl<TbCountinuousDao,TbCountinuousRollingSteelGrade> implements TbCountinuousService {

    @Autowired
    private TbCountinuousDao tbCountinuousDao;


    public ResultData insertDataTbCountinuous(String data){
        try{
            TbCountinuousRollingSteelGrade tbCountinuousRollingSteelGrade= JSON.parseObject(data,TbCountinuousRollingSteelGrade.class);
            this.save(tbCountinuousRollingSteelGrade);
            return ResultData.ResultDataSuccessSelf("添加数据成功", null);
        }catch (Exception e){
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("添加失败，错误信息为" + e.getMessage(), null);
        }

    };

    @Override
    public ResultData deleteDataTbCountinuousOne(String steelgrade) {
        try {
            tbCountinuousDao.deleteBySteelGrade(steelgrade);
            return ResultData.ResultDataSuccessSelf("删除数据数据成功", null);
        }catch (Exception e){
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("删除失败,失败信息为" + e.getMessage(), null);
        }
    }

    /**
     * 分页查看记录
     * @param data 分页参数字符串
     */
    public ResultData findDataTbCountinuousByPage(String data) {
        try {
            TbCountinuousReq tbCountinuousReq= JSON.parseObject(data,TbCountinuousReq.class);
            Integer pageIndex = tbCountinuousReq.getPageIndex();
            Integer pageSize = tbCountinuousReq.getPageSize();
            if(null == pageIndex || null == pageSize){
                return ResultData.ResultDataFaultSelf("分页参数没有传", null);
            }
            QueryWrapper<TbCountinuousRollingSteelGrade> queryWrapper = new QueryWrapper<TbCountinuousRollingSteelGrade>();

            Page<TbCountinuousRollingSteelGrade> page = new Page<TbCountinuousRollingSteelGrade>(pageIndex, pageSize);

            IPage<TbCountinuousRollingSteelGrade> list = tbCountinuousDao.selectPage(page, queryWrapper);

            return ResultData.ResultDataSuccess(list, (int)list.getTotal());


        }catch (Exception e){
            e.printStackTrace();
            return ResultData.ResultDataFaultSelf("查询失败,失败信息为" + e.getMessage(), null);
        }
    }




}
